package com.hunttown.mes.convert;

import com.google.common.collect.Lists;
import com.hunttown.mes.common.utils.BeanUtils;
import com.hunttown.mes.domain.AnalysisManageRightRoleMenuRel;
import com.hunttown.mes.rpc.domain.AnalysisManageRightRoleMenuRelDTO;
import com.hunttown.mes.rpc.domain.enums.ErrorCode;
import com.hunttown.mes.rpc.exception.ConvertException;
import org.apache.commons.collections.CollectionUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.Collections;
import java.util.List;

/**
 * created by wangjunfu on 2018-11-26 15:06:01
 */
public class AnalysisManageRightRoleMenuRelConverts {

    private static Logger LOG = LoggerFactory.getLogger(AnalysisManageRightRoleMenuRelConverts.class);

    public static List<AnalysisManageRightRoleMenuRelDTO> convert(List<AnalysisManageRightRoleMenuRel> analysisManageRightRoleMenuRelList) {
        if (CollectionUtils.isEmpty(analysisManageRightRoleMenuRelList)) {
            return Collections.EMPTY_LIST;
        }

        List<AnalysisManageRightRoleMenuRelDTO> analysisManageRightRoleMenuRelListResult = Lists.newArrayList();
        for (AnalysisManageRightRoleMenuRel analysisManageRightRoleMenuRel : analysisManageRightRoleMenuRelList) {
            analysisManageRightRoleMenuRelListResult.add(convert(analysisManageRightRoleMenuRel));
        }
        return analysisManageRightRoleMenuRelListResult;
    }

    public static AnalysisManageRightRoleMenuRelDTO convert(AnalysisManageRightRoleMenuRel analysisManageRightRoleMenuRel) {
        try {
            return BeanUtils.copy(analysisManageRightRoleMenuRel, AnalysisManageRightRoleMenuRelDTO.class);
        } catch (Exception e) {
            LOG.error("AnalysisManageRightRoleMenuRel到AnalysisManageRightRoleMenuRelDTO转换失败!", e);
            throw new ConvertException(ErrorCode.CONVERT_ERROR, "AnalysisManageRightRoleMenuRel到AnalysisManageRightRoleMenuRelDTO转换失败", e);
        }
    }

    public static AnalysisManageRightRoleMenuRel convert(AnalysisManageRightRoleMenuRelDTO analysisManageRightRoleMenuRelDTO) {
        try {
            return BeanUtils.copy(analysisManageRightRoleMenuRelDTO, AnalysisManageRightRoleMenuRel.class);
        } catch (Exception e) {
            LOG.error("AnalysisManageRightRoleMenuRelDTO到AnalysisManageRightRoleMenuRel转换失败!", e);
            throw new ConvertException(ErrorCode.CONVERT_ERROR, "AnalysisManageRightRoleMenuRelDTO到AnalysisManageRightRoleMenuRel转换失败", e);
        }
    }

    public static List<AnalysisManageRightRoleMenuRel> converto(List<AnalysisManageRightRoleMenuRelDTO> analysisManageRightRoleMenuRelDTOS) {
        if (CollectionUtils.isEmpty(analysisManageRightRoleMenuRelDTOS)) {
            return Collections.EMPTY_LIST;
        }

        List<AnalysisManageRightRoleMenuRel> manageRightRoleMenuRelListResult = Lists.newArrayList();
        for (AnalysisManageRightRoleMenuRelDTO manageRightRoleMenuRel : analysisManageRightRoleMenuRelDTOS) {
            manageRightRoleMenuRelListResult.add(convert(manageRightRoleMenuRel));
        }
        return manageRightRoleMenuRelListResult;
    }
}